package com.sys.stat.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sys.common.pojo.ApiResponse;
import com.sys.common.pojo.ApiResponseEnum;
import com.sys.common.service.BaseServiceImpl;
import com.sys.common.util.ConstatFinalUtil;
import com.sys.common.util.PageInfoUtil;
import com.sys.stat.dao.IAStatDao;
import com.sys.stat.service.IStatDbService;

/**
 * 统计 Db 相关的统计 (实现类)
 * 
 * @author Tm
 *
 */
@Service("statDbService")
public class StatDbServiceImpl extends BaseServiceImpl implements IStatDbService {
	@Autowired
	private IAStatDao statDao;

	public ApiResponse<Map<String, Object>> statOrdersDayService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap) {
		ApiResponse<Map<String, Object>> apiResponse = new ApiResponse<Map<String, Object>>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<Map<String, Object>> demoCateList = Collections.EMPTY_LIST;

		Map<String, List<Map<String, Object>>> dataList = new HashMap<String, List<Map<String, Object>>>();
		if (pageInfoUtil != null) {
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoCateList = this.statDao.statOrdersDay(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		} else {
			demoCateList = this.statDao.statOrdersDay(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoCateList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoCateList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

}
